<!DOCTYPE html><html><head>
      <title>&#x7406;&#x89E3;&#x7BAD;&#x5934;&#x51FD;&#x6570;&#x4E2D;&#x7684;this</title>
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      
      <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.10.0-rc.1/dist/katex.min.css">
      
      
      
      
      
      
      
      
      

      <style> 
      pre{font-family:Menlo,Monaco,Consolas,'Courier New',monospace;direction:ltr;text-align:left;white-space:pre;word-spacing:normal;word-break:normal;padding:1em;margin:.5em 0;overflow:auto;line-height:1.5;tab-size:4;hyphens:none;color:#c5c8c6;background-color:#27292c !important;border:#43484c;border-radius:3px}pre[class*="language-"]{padding:1em}code[class*="language-"] .token.comment,pre[class*="language-"] .token.comment,code[class*="language-"] .token.prolog,pre[class*="language-"] .token.prolog,code[class*="language-"] .token.doctype,pre[class*="language-"] .token.doctype,code[class*="language-"] .token.cdata,pre[class*="language-"] .token.cdata{color:#7C7C7C}code[class*="language-"] .token.punctuation,pre[class*="language-"] .token.punctuation{color:#96CBFE}code[class*="language-"] .namespace,pre[class*="language-"] .namespace{opacity:.7}code[class*="language-"] .token.constant,pre[class*="language-"] .token.constant{color:#99CC99}code[class*="language-"] .token.boolean,pre[class*="language-"] .token.boolean,code[class*="language-"] .token.number,pre[class*="language-"] .token.number,code[class*="language-"] .token.function-name,pre[class*="language-"] .token.function-name{color:#FF73FD}code[class*="language-"] .token.tag,pre[class*="language-"] .token.tag{color:#96CBFE}code[class*="language-"] .token.selector,pre[class*="language-"] .token.selector{color:#96CBFE}code[class*="language-"] .token.attr-name,pre[class*="language-"] .token.attr-name{color:#C6C5FE}code[class*="language-"] .token.string,pre[class*="language-"] .token.string{color:#A8FF60}code[class*="language-"] .token.char,pre[class*="language-"] .token.char{color:#FF8000}code[class*="language-"] .token.entity,pre[class*="language-"] .token.entity{color:#FFD2A7}code[class*="language-"] .token.url,pre[class*="language-"] .token.url{color:#7C7C7C}code[class*="language-"] .token.operator,pre[class*="language-"] .token.operator{color:#EDEDED}code[class*="language-"] .token.atrule,pre[class*="language-"] .token.atrule,code[class*="language-"] .token.attr-value,pre[class*="language-"] .token.attr-value,code[class*="language-"] .token.keyword,pre[class*="language-"] .token.keyword{color:#CFCB90}code[class*="language-"] .token.function,pre[class*="language-"] .token.function{color:#FFD2A7}code[class*="language-"] .token.class-name,pre[class*="language-"] .token.class-name{color:#FFD2A7}code[class*="language-"] .token.variable,pre[class*="language-"] .token.variable{color:#C6C5FE}code[class*="language-"] .token.regex,pre[class*="language-"] .token.regex,code[class*="language-"] .token.important,pre[class*="language-"] .token.important{color:#E9C062}code[class*="language-"] .token.important,pre[class*="language-"] .token.important,code[class*="language-"] .token.bold,pre[class*="language-"] .token.bold{font-weight:bold}code[class*="language-"] .token.italic,pre[class*="language-"] .token.italic{font-style:italic}code[class*="language-"] .token.entity,pre[class*="language-"] .token.entity{cursor:help}html body{font-family:"Helvetica Neue",Helvetica,"Segoe UI",Arial,freesans,sans-serif;font-size:16px;line-height:1.6;color:#c5c8c6;background-color:#1d1f21;overflow:initial;box-sizing:border-box;word-wrap:break-word}html body>:first-child{margin-top:0}html body h1,html body h2,html body h3,html body h4,html body h5,html body h6{line-height:1.2;margin-top:1em;margin-bottom:16px;color:#fff}html body h1{font-size:2.25em;font-weight:300;padding-bottom:.3em}html body h2{font-size:1.75em;font-weight:400;padding-bottom:.3em}html body h3{font-size:1.5em;font-weight:500}html body h4{font-size:1.25em;font-weight:600}html body h5{font-size:1.1em;font-weight:600}html body h6{font-size:1em;font-weight:600}html body h1,html body h2,html body h3,html body h4,html body h5{font-weight:600}html body h5{font-size:1em}html body h6{color:#9ba09d}html body strong{color:#fff}html body del{color:#9ba09d}html body a:not([href]){color:inherit;text-decoration:none}html body a{color:#ddd;text-decoration:none}html body a:hover{color:#cecece;text-decoration:none}html body img{max-width:100%}html body>p{margin-top:0;margin-bottom:16px;word-wrap:break-word}html body>ul,html body>ol{margin-bottom:16px}html body ul,html body ol{padding-left:2em}html body ul.no-list,html body ol.no-list{padding:0;list-style-type:none}html body ul ul,html body ul ol,html body ol ol,html body ol ul{margin-top:0;margin-bottom:0}html body li{margin-bottom:0}html body li.task-list-item{list-style:none}html body li>p{margin-top:0;margin-bottom:0}html body .task-list-item-checkbox{margin:0 .2em .25em -1.8em;vertical-align:middle}html body .task-list-item-checkbox:hover{cursor:pointer}html body blockquote{margin:16px 0;font-size:inherit;padding:0 15px;color:#9ba09d;border-left:4px solid #43484c}html body blockquote>:first-child{margin-top:0}html body blockquote>:last-child{margin-bottom:0}html body hr{height:4px;margin:32px 0;background-color:#43484c;border:0 none}html body table{margin:10px 0 15px 0;border-collapse:collapse;border-spacing:0;display:block;width:100%;overflow:auto;word-break:normal;word-break:keep-all}html body table th{font-weight:bold;color:#fff}html body table td,html body table th{border:1px solid #43484c;padding:6px 13px}html body dl{padding:0}html body dl dt{padding:0;margin-top:16px;font-size:1em;font-style:italic;font-weight:bold}html body dl dd{padding:0 16px;margin-bottom:16px}html body code{font-family:Menlo,Monaco,Consolas,'Courier New',monospace;font-size:.85em !important;color:#fff;background-color:#303337;border-radius:3px;padding:.2em 0}html body code::before,html body code::after{letter-spacing:-0.2em;content:"\00a0"}html body pre>code{padding:0;margin:0;font-size:.85em !important;word-break:normal;white-space:pre;background:transparent;border:0}html body .highlight{margin-bottom:16px}html body .highlight pre,html body pre{padding:1em;overflow:auto;font-size:.85em !important;line-height:1.45;border:#43484c;border-radius:3px}html body .highlight pre{margin-bottom:0;word-break:normal}html body pre code,html body pre tt{display:inline;max-width:initial;padding:0;margin:0;overflow:initial;line-height:inherit;word-wrap:normal;background-color:transparent;border:0}html body pre code:before,html body pre tt:before,html body pre code:after,html body pre tt:after{content:normal}html body p,html body blockquote,html body ul,html body ol,html body dl,html body pre{margin-top:0;margin-bottom:16px}html body kbd{color:#fff;border:1px solid #43484c;border-bottom:2px solid #35393c;padding:2px 4px;background-color:#303337;border-radius:3px}@media print{html body{background-color:#1d1f21}html body h1,html body h2,html body h3,html body h4,html body h5,html body h6{color:#fff;page-break-after:avoid}html body blockquote{color:#9ba09d}html body pre{page-break-inside:avoid}html body table{display:table}html body img{display:block;max-width:100%;max-height:100%}html body pre,html body code{word-wrap:break-word;white-space:pre}}html body a{text-decoration:underline}.markdown-preview{width:100%;height:100%;box-sizing:border-box}.markdown-preview .pagebreak,.markdown-preview .newpage{page-break-before:always}.markdown-preview pre.line-numbers{position:relative;padding-left:3.8em;counter-reset:linenumber}.markdown-preview pre.line-numbers>code{position:relative}.markdown-preview pre.line-numbers .line-numbers-rows{position:absolute;pointer-events:none;top:1em;font-size:100%;left:0;width:3em;letter-spacing:-1px;border-right:1px solid #999;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.markdown-preview pre.line-numbers .line-numbers-rows>span{pointer-events:none;display:block;counter-increment:linenumber}.markdown-preview pre.line-numbers .line-numbers-rows>span:before{content:counter(linenumber);color:#999;display:block;padding-right:.8em;text-align:right}.markdown-preview .mathjax-exps .MathJax_Display{text-align:center !important}.markdown-preview:not([for="preview"]) .code-chunk .btn-group{display:none}.markdown-preview:not([for="preview"]) .code-chunk .status{display:none}.markdown-preview:not([for="preview"]) .code-chunk .output-div{margin-bottom:16px}.scrollbar-style::-webkit-scrollbar{width:8px}.scrollbar-style::-webkit-scrollbar-track{border-radius:10px;background-color:transparent}.scrollbar-style::-webkit-scrollbar-thumb{border-radius:5px;background-color:rgba(150,150,150,0.66);border:4px solid rgba(150,150,150,0.66);background-clip:content-box}html body[for="html-export"]:not([data-presentation-mode]){position:relative;width:100%;height:100%;top:0;left:0;margin:0;padding:0;overflow:auto}html body[for="html-export"]:not([data-presentation-mode]) .markdown-preview{position:relative;top:0}@media screen and (min-width:914px){html body[for="html-export"]:not([data-presentation-mode]) .markdown-preview{padding:2em calc(50% - 457px)}}@media screen and (max-width:914px){html body[for="html-export"]:not([data-presentation-mode]) .markdown-preview{padding:2em}}@media screen and (max-width:450px){html body[for="html-export"]:not([data-presentation-mode]) .markdown-preview{font-size:14px !important;padding:1em}}@media print{html body[for="html-export"]:not([data-presentation-mode]) #sidebar-toc-btn{display:none}}html body[for="html-export"]:not([data-presentation-mode]) #sidebar-toc-btn{position:fixed;bottom:8px;left:8px;font-size:28px;cursor:pointer;color:inherit;z-index:99;width:32px;text-align:center;opacity:.4}html body[for="html-export"]:not([data-presentation-mode])[html-show-sidebar-toc] #sidebar-toc-btn{opacity:1}html body[for="html-export"]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc{position:fixed;top:0;left:0;width:300px;height:100%;padding:32px 0 48px 0;font-size:14px;box-shadow:0 0 4px rgba(150,150,150,0.33);box-sizing:border-box;overflow:auto;background-color:inherit}html body[for="html-export"]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc::-webkit-scrollbar{width:8px}html body[for="html-export"]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc::-webkit-scrollbar-track{border-radius:10px;background-color:transparent}html body[for="html-export"]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc::-webkit-scrollbar-thumb{border-radius:5px;background-color:rgba(150,150,150,0.66);border:4px solid rgba(150,150,150,0.66);background-clip:content-box}html body[for="html-export"]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc a{text-decoration:none}html body[for="html-export"]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc ul{padding:0 1.6em;margin-top:.8em}html body[for="html-export"]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc li{margin-bottom:.8em}html body[for="html-export"]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc ul{list-style-type:none}html body[for="html-export"]:not([data-presentation-mode])[html-show-sidebar-toc] .markdown-preview{left:300px;width:calc(100% -  300px);padding:2em calc(50% - 457px -  150px);margin:0;box-sizing:border-box}@media screen and (max-width:1274px){html body[for="html-export"]:not([data-presentation-mode])[html-show-sidebar-toc] .markdown-preview{padding:2em}}@media screen and (max-width:450px){html body[for="html-export"]:not([data-presentation-mode])[html-show-sidebar-toc] .markdown-preview{width:100%}}html body[for="html-export"]:not([data-presentation-mode]):not([html-show-sidebar-toc]) .markdown-preview{left:50%;transform:translateX(-50%)}html body[for="html-export"]:not([data-presentation-mode]):not([html-show-sidebar-toc]) .md-sidebar-toc{display:none}
/* Please visit the URL below for more information: */
/*   https://shd101wyy.github.io/markdown-preview-enhanced/#/customize-css */
 
      </style>
    </head>
    <body for="html-export">
      <div class="mume markdown-preview   ">
      <p>javascript,es6+</p>
<h1 class="mume-header" id="%E4%B8%80%E5%8F%A5%E8%AF%9D%E6%98%8E%E7%99%BD%E7%AE%AD%E5%A4%B4%E5%87%BD%E6%95%B0%E4%B8%AD%E7%9A%84this">&#x4E00;&#x53E5;&#x8BDD;&#x660E;&#x767D;&#x7BAD;&#x5934;&#x51FD;&#x6570;&#x4E2D;&#x7684;this</h1>

<p>&#x5173;&#x4E8E;&#x7BAD;&#x5934;&#x51FD;&#x6570;&#x4E2D;this&#x503C;&#x7684;&#x95EE;&#x9898;&#xFF0C;&#x7F51;&#x4E0A;&#x67E5;&#x67E5;&#xFF0C;&#x4F1A;&#x544A;&#x8BC9;&#x4F60; &#x201C;&#x7BAD;&#x5934;&#x51FD;&#x6570;&#x7684;this&#x56FA;&#x5B9A;&#x5316;&#xFF0C;&#x7BAD;&#x5934;&#x51FD;&#x6570;&#x4E2D;&#x7684;this&#x7ED1;&#x5B9A;&#x5B9A;&#x4E49;&#x65F6;&#x6240;&#x5728;&#x7684;&#x4F5C;&#x7528;&#x57DF;......&#x201D;&#xFF0C;&#x597D;&#x7ED5;&#xFF01;</p>
<blockquote>
<p>&#x7BAD;&#x5934;&#x51FD;&#x6570;&#x4E2D;this&#x5012;&#x5E95;&#x6307;&#x5411;&#x8C01;&#xFF1F;&#x4E00;&#x53E5;&#x8BDD;&#xFF0C;<strong>&#x7BAD;&#x5934;&#x51FD;&#x6570;&#x5185;&#x7684;this&#x5C31;&#x662F;&#x7BAD;&#x5934;&#x51FD;&#x6570;&#x5916;&#x7684;&#x90A3;&#x4E2A;this&#xFF01;</strong> &#x4E3A;&#x4EC0;&#x4E48;&#xFF1F;&#x56E0;&#x4E3A;&#x7BAD;&#x5934;&#x51FD;&#x6570;&#x6CA1;&#x6709;&#x81EA;&#x5DF1;&#x7684;this&#x3002;<br>
&#x5982;&#x679C;&#x4F60;&#x5DF2;&#x660E;&#x767D;&#x8FD9;&#x53E5;&#x8BDD;&#x7684;&#x610F;&#x601D;&#xFF0C;&#x90A3;&#x4E48;&#x672C;&#x6587;&#x5230;&#x6B64;&#x7ED3;&#x675F;&#xFF0C;&#x4F60;&#x53EF;&#x4EE5;&#x53BB;&#x770B;&#x770B;&#x522B;&#x7684;&#x66F4;&#x6709;&#x8425;&#x517B;&#x7684;&#x4E1C;&#x897F;&#x4E86;&#x3002;<br>
&#x5982;&#x679C;&#x6211;&#x8FD9;&#x53E5;&#x8BDD;&#x63CF;&#x8FF0;&#x7684;&#x4E0D;&#x591F;&#x6E05;&#x695A;&#xFF0C;&#x6216;&#x4F60;&#x5BF9;&#x5B83;&#x6709;&#x6000;&#x7591;&#xFF0C;&#x8BF7;&#x7EE7;&#x7EED;&#x5F80;&#x4E0B;&#x770B;&#x3002;&#x5982;&#x679C;&#x8BF4;&#x9519;&#x4E86;&#x8BF7;&#x4F7F;&#x52B2;&#x62CD;&#x7816;&#x3002;</p>
</blockquote>
<p><strong>&#x76F4;&#x63A5;&#x4E0A;&#x4EE3;&#x7801;&#xFF01;</strong></p>
<blockquote>
<p>&#x6CE8;&#xFF1A;&#x4EE5;&#x4E0B;&#x4EE3;&#x7801;&#x5168;&#x57FA;&#x4E8E;&#x6D4F;&#x89C8;&#x5668;&#x975E;&#x4E25;&#x683C;&#x6A21;&#x5F0F;&#x8FD0;&#x884C;&#xFF0C;&#x4E14;&#x5047;&#x5B9A;&#x4F60;&#x5DF2;&#x7ECF;&#x5BF9;&#x975E;&#x7BAD;&#x5934;&#x51FD;&#x6570;&#x4E2D;&#x7684;this&#x5168;&#x7136;&#x4E86;&#x89E3;</p>
</blockquote>
<p>&#x54B1;&#x5148;&#x5B9A;&#x4E49;&#x4E00;&#x4E2A;&#x5168;&#x5C40;&#x53D8;&#x91CF;a&#xFF0C;&#x540E;&#x9762;&#x6240;&#x6709;&#x7684;&#x793A;&#x4F8B;&#x90FD;&#x5047;&#x5B9A;&#x6B64;&#x5168;&#x5C40;&#x53D8;&#x91CF;&#x5DF2;&#x5B58;&#x5728;:</p>
<pre data-role="codeBlock" data-info="javascript" class="language-javascript"><span class="token keyword">var</span> a <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span>
</pre><h4 class="mume-header" id="%E7%AC%AC%E4%B8%80%E4%B8%AA%E7%A4%BA%E4%BE%8B">&#x7B2C;&#x4E00;&#x4E2A;&#x793A;&#x4F8B;&#xFF1A;</h4>

<pre data-role="codeBlock" data-info="javascript" class="language-javascript"><span class="token comment">// demo1</span>
<span class="token keyword">var</span> obj <span class="token operator">=</span>  <span class="token punctuation">{</span>
  a<span class="token punctuation">:</span> <span class="token number">1</span><span class="token punctuation">,</span>
  b1<span class="token punctuation">:</span> <span class="token keyword">this</span><span class="token punctuation">.</span>a<span class="token punctuation">,</span>
  b2<span class="token punctuation">:</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token keyword">this</span><span class="token punctuation">.</span>a<span class="token punctuation">,</span>
<span class="token punctuation">}</span><span class="token punctuation">;</span>

console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>obj<span class="token punctuation">.</span>b1<span class="token punctuation">)</span><span class="token punctuation">;</span>  <span class="token comment">// 0</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>obj<span class="token punctuation">.</span><span class="token function">b2</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>  <span class="token comment">// 0</span>
</pre><p>&#x6839;&#x636E;&#x7ED3;&#x679C;&#x53EF;&#x4EE5;&#x770B;&#x5230;obj&#x5BF9;&#x8C61;&#x4E2D;&#x7684;&#x5C5E;&#x6027;b1&#x7684;&#x503C;&#x6765;&#x81EA;<strong>&#x5168;&#x5C40;&#x53D8;&#x91CF;a</strong>&#xFF0C;&#x800C;&#x4E0D;&#x662F;<strong>obj&#x5BF9;&#x8C61;&#x7684;&#x5C5E;&#x6027;a</strong>,&#x4E5F;&#x5C31;&#x662F;&#x8BF4;<code>b1: this.a,</code>&#x4E2D;&#x7684;this&#x6307;&#x5411;window&#x3002;&#x800C;<code>b2: () =&gt; this.a,</code>&#x4E2D;&#x7684;this&#x540C;&#x6837;&#x6307;&#x5411;window&#xFF0C;&#x8FD4;&#x56DE;&#x5168;&#x5C40;&#x53D8;&#x91CF;a&#x7684;&#x503C;&#x3002;</p>
<h4 class="mume-header" id="%E7%AC%AC%E4%BA%8C%E4%B8%AA%E7%A4%BA%E4%BE%8B">&#x7B2C;&#x4E8C;&#x4E2A;&#x793A;&#x4F8B;&#xFF1A;</h4>

<pre data-role="codeBlock" data-info="javascript" class="language-javascript"><span class="token comment">// demo2</span>
<span class="token punctuation">(</span><span class="token keyword">function</span> <span class="token function">fn</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
  <span class="token keyword">var</span> a <span class="token operator">=</span> <span class="token number">2</span><span class="token punctuation">;</span>
  console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span>a<span class="token punctuation">)</span><span class="token punctuation">;</span>  <span class="token comment">// 0</span>

  <span class="token keyword">const</span> <span class="token function-variable function">subf</span> <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">=&gt;</span><span class="token keyword">this</span><span class="token punctuation">.</span>a<span class="token punctuation">;</span>
  console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token function">subf</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// 0</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
</pre><h4 class="mume-header" id="%E7%AC%AC%E4%B8%89%E4%B8%AA%E7%A4%BA%E4%BE%8B">&#x7B2C;&#x4E09;&#x4E2A;&#x793A;&#x4F8B;&#xFF1A;</h4>

<pre data-role="codeBlock" data-info="javascript" class="language-javascript"><span class="token comment">// demo3</span>
<span class="token keyword">var</span> obj2 <span class="token operator">=</span>  <span class="token punctuation">{</span>
  a<span class="token punctuation">:</span> <span class="token number">3</span><span class="token punctuation">,</span>
  b1<span class="token punctuation">:</span> <span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span> <span class="token keyword">return</span> <span class="token keyword">this</span><span class="token punctuation">.</span>a<span class="token punctuation">;</span><span class="token punctuation">}</span><span class="token punctuation">,</span>
  b2<span class="token punctuation">:</span> <span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span> <span class="token keyword">return</span> <span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">=&gt;</span><span class="token keyword">this</span><span class="token punctuation">.</span>a<span class="token punctuation">}</span><span class="token punctuation">,</span>
<span class="token punctuation">}</span><span class="token punctuation">;</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>obj2<span class="token punctuation">.</span><span class="token function">b1</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>  <span class="token comment">// 3</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>obj2<span class="token punctuation">.</span><span class="token function">b2</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>  <span class="token comment">// 3</span>
</pre><p>&#x8FD9;&#x4E2A;&#x793A;&#x4F8B;&#x4E2D;&#x7BAD;&#x5934;&#x51FD;&#x6570;&#x5916;&#x7684;this&#x662F;&#x54EA;&#x4E2A;&#xFF1F;&#x6211;&#x4EEC;&#x5728;&#x7BAD;&#x5934;&#x51FD;&#x6570;&#x5916;&#x9762;&#x52A0;&#x4E2A;this.a&#x770B;&#x770B;&#xFF1A;</p>
<pre data-role="codeBlock" data-info="javascript" class="language-javascript"><span class="token keyword">var</span> obj2 <span class="token operator">=</span>  <span class="token punctuation">{</span>
  a<span class="token punctuation">:</span> <span class="token number">3</span><span class="token punctuation">,</span>
  b1<span class="token punctuation">:</span> <span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span> <span class="token keyword">return</span> <span class="token keyword">this</span><span class="token punctuation">.</span>a<span class="token punctuation">;</span><span class="token punctuation">}</span><span class="token punctuation">,</span>
  b2<span class="token punctuation">:</span> <span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span> <span class="token keyword">return</span> <span class="token keyword">this</span><span class="token punctuation">.</span>a<span class="token punctuation">,</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">=&gt;</span><span class="token keyword">this</span><span class="token punctuation">.</span>a<span class="token punctuation">}</span><span class="token punctuation">,</span>
<span class="token punctuation">}</span><span class="token punctuation">;</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>obj2<span class="token punctuation">.</span><span class="token function">b1</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>  <span class="token comment">// 3</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>obj2<span class="token punctuation">.</span><span class="token function">b2</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>  <span class="token comment">// 3</span>
</pre><h4 class="mume-header" id="%E7%AC%AC%E5%9B%9B%E4%B8%AA%E7%A4%BA%E4%BE%8B">&#x7B2C;&#x56DB;&#x4E2A;&#x793A;&#x4F8B;&#xFF1A;</h4>

<pre data-role="codeBlock" data-info="javascript" class="language-javascript"><span class="token comment">// demo4</span>
<span class="token keyword">var</span> obj3 <span class="token operator">=</span>  <span class="token punctuation">{</span>
  a<span class="token punctuation">:</span> <span class="token number">4</span><span class="token punctuation">,</span>
  b1<span class="token punctuation">:</span> <span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span> <span class="token keyword">return</span> <span class="token keyword">this</span><span class="token punctuation">.</span>a<span class="token punctuation">;</span><span class="token punctuation">}</span><span class="token punctuation">,</span>
  b2<span class="token punctuation">:</span> <span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span> <span class="token keyword">return</span> <span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">=&gt;</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token keyword">this</span><span class="token punctuation">.</span>a<span class="token punctuation">}</span><span class="token punctuation">,</span>
<span class="token punctuation">}</span><span class="token punctuation">;</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>obj4<span class="token punctuation">.</span><span class="token function">b1</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>  <span class="token comment">// 4</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>obj4<span class="token punctuation">.</span><span class="token function">b2</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>  <span class="token comment">// 4</span>
</pre><p>&#x8FD9;&#x91CC;&#x7BAD;&#x5934;&#x51FD;&#x6570;&#x8FD4;&#x56DE;&#x7BAD;&#x5934;&#x51FD;&#x6570;&#x518D;&#x8FD4;&#x56DE;&#x7BAD;&#x5934;&#x51FD;&#x6570;&#xFF0C;&#x6700;&#x540E;&#x4E00;&#x4E2A;&#x7BAD;&#x5934;&#x51FD;&#x6570;&#x8FD4;&#x56DE;this.a&#x3002;&#x8FD9;&#x4E2A;this&#x662F;&#x8C01;&#xFF1F;&#x5C31;&#x662F;&#x6700;&#x540E;&#x7BAD;&#x5934;&#x51FD;&#x6570;&#x5916;&#x9762;&#x7684;&#x5916;&#x9762;&#x7684;&#x5916;&#x9762;&#x7684;&#x90A3;&#x4E2A;this,&#x4E5F;&#x5C31;&#x662F;obj3.b1&#x4E2D;&#x7684;&#x90A3;&#x4E2A;this&#xFF0C;&#x4E5F;&#x5C31;&#x662F;obj3.a&#x3002;&#x1F603;<br>
&#x5B9E;&#x60C5;&#x662F;&#x8FD9;&#x6837;&#xFF1A;&#x7BAD;&#x5934;&#x51FD;&#x6570;&#x6CA1;&#x6709;&#x81EA;&#x5DF1;&#x7684;this&#xFF0C;&#x6240;&#x4EE5;&#x4E0D;&#x7BA1;&#x5D4C;&#x5957;&#x591A;&#x5C11;&#x5C42;&#xFF0C;&#x90FD;&#x4E0D;&#x5F71;&#x54CD;this&#x662F;&#x8C01;&#x3002;</p>
<h4 class="mume-header" id="%E7%AC%AC%E4%BA%94%E4%B8%AA%E7%A4%BA%E4%BE%8B">&#x7B2C;&#x4E94;&#x4E2A;&#x793A;&#x4F8B;&#xFF1A;</h4>

<pre data-role="codeBlock" data-info="javascript" class="language-javascript"><span class="token comment">// demo5</span>
<span class="token keyword">function</span> <span class="token function">f0</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">var</span> a <span class="token operator">=</span> <span class="token number">5</span><span class="token punctuation">;</span>

  <span class="token function">setTimeout</span><span class="token punctuation">(</span><span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">var</span> b1 <span class="token operator">=</span> <span class="token keyword">this</span><span class="token punctuation">.</span>a<span class="token punctuation">;</span>
    console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>b1<span class="token punctuation">)</span><span class="token punctuation">;</span>  <span class="token comment">// 0</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token number">100</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

  <span class="token function">setTimeout</span><span class="token punctuation">(</span><span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">var</span> <span class="token function-variable function">b2</span> <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">=&gt;</span> <span class="token keyword">this</span><span class="token punctuation">.</span>a<span class="token punctuation">;</span>
    console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token function">b2</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>  <span class="token comment">// 0</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token number">200</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token function">f0</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// 0  0</span>
</pre><p>&#x6211;&#x4EEC;&#x90FD;&#x77E5;&#x9053;setTimeout&#x4E2D;&#x7684;&#x90A3;&#x4E2A;function&#x8FD0;&#x884C;&#x4E8E;&#x5168;&#x5C40;&#x73AF;&#x5883;&#x4E0B;&#xFF0C;&#x56E0;&#x6B64;&#x91CC;&#x9762;&#x7684;this&#x6307;&#x5411;window&#x3002;&#x800C;&#x7BAD;&#x5934;&#x51FD;&#x6570;&#x6CA1;&#x6709;&#x81EA;&#x5DF1;&#x7684;this&#xFF0C;&#x6240;&#x4EE5;&#x7B2C;&#x4E8C;&#x4E2A;setTimeout&#x4E2D;&#x7BAD;&#x5934;&#x51FD;&#x6570;&#x7684;this&#x4E5F;&#x6307;&#x5411;window.</p>
<p>&#x90A3;&#x4E48;setTimeout&#x7684;&#x7B2C;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x4F7F;&#x7528;&#x7BAD;&#x5934;&#x51FD;&#x6570;&#x4F1A;&#x662F;&#x4E2A;&#x4EC0;&#x4E48;&#x60C5;&#x51B5;&#xFF1F;&#x770B;&#x4E0B;&#x4E00;&#x4E2A;&#x793A;&#x4F8B;&#x3002;</p>
<h4 class="mume-header" id="%E7%AC%AC%E5%85%AD%E4%B8%AA%E7%A4%BA%E4%BE%8B">&#x7B2C;&#x516D;&#x4E2A;&#x793A;&#x4F8B;&#xFF1A;</h4>

<pre data-role="codeBlock" data-info="javascript" class="language-javascript"><span class="token comment">// demo6</span>
<span class="token keyword">function</span> <span class="token function">f1</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span>a<span class="token punctuation">)</span><span class="token punctuation">;</span> 
  <span class="token function">setTimeout</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
    console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span>a<span class="token punctuation">)</span><span class="token punctuation">;</span>  
  <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token number">100</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token function">f1</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// 0  0</span>
</pre><p>&#x8FD9;&#x91CC;&#x7BAD;&#x5934;&#x51FD;&#x6570;&#x4F5C;&#x4E3A;setTimeout&#x7684;&#x7B2C;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#xFF0C;&#x7BAD;&#x5934;&#x51FD;&#x6570;&#x5916;&#x9762;&#x7684;&#x90A3;&#x4E2A;this&#x662F;&#x8C01;?&#x628A;&#x7BAD;&#x5934;&#x51FD;&#x6570;&#x6362;&#x6210;<code>this.fn()</code>&#xFF1A;</p>
<pre data-role="codeBlock" data-info="javascript" class="language-javascript"><span class="token keyword">function</span> <span class="token function">f1</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span>a<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// 0</span>
  <span class="token function">setTimeout</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">fn</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">,</span> <span class="token number">100</span><span class="token punctuation">)</span><span class="token punctuation">;</span> 
<span class="token punctuation">}</span>
</pre><p>&#x6211;&#x4EEC;&#x8FD9;&#x91CC;&#x4E0D;&#x7528;&#x4E86;&#x89E3;this.fn()&#x6709;&#x4EC0;&#x4E48;&#x529F;&#x80FD;&#xFF0C;&#x770B;&#x5230;&#x5B83;&#x6211;&#x4EEC;&#x5C31;&#x4F1A;&#x660E;&#x767D;&#x4E86;this.fn()&#x4E2D;&#x7684;this&#x548C;&#x524D;&#x9762;&#x4E00;&#x884C;&#x4E2D;&#x7684;this.a&#x4E2D;&#x7684;this&#x662F;&#x540C;&#x4E00;&#x4E2A;this&#x3002;</p>
<p>&#x6269;&#x5C55;&#x4E00;&#x4E0B;&#xFF1A;</p>
<pre data-role="codeBlock" data-info="javascript" class="language-javascript"><span class="token comment">// &#x8FD9;&#x6837;&#x6267;&#x884C;</span>
f1<span class="token punctuation">.</span><span class="token function">call</span><span class="token punctuation">(</span><span class="token punctuation">{</span>a<span class="token punctuation">:</span> <span class="token number">7</span><span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>  <span class="token comment">// 7  7</span>
</pre><p>&#x7ED3;&#x679C;&#x662F;&#x8F93;&#x51FA;&#x4E24;&#x4E2A;7,<br>
&#x4E3A;&#x4EC0;&#x4E48;&#xFF1F;</p>
<pre data-role="codeBlock" data-info="javascript" class="language-javascript"><span class="token comment">// demo6</span>
<span class="token keyword">function</span> <span class="token function">f1</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span>a<span class="token punctuation">)</span><span class="token punctuation">;</span>   <span class="token comment">// &#x56E0;&#x4E3A;&#x901A;&#x8FC7;call&#x5BF9;this&#x7684;&#x7ED1;&#x5B9A;&#xFF0C;f1&#x4E2D;&#x7684;this&#x6307;&#x5411; {a: 7}</span>
  <span class="token function">setTimeout</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
    console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span>a<span class="token punctuation">)</span><span class="token punctuation">;</span>  <span class="token comment">// &#x540C;&#x6837;&#x8FD9;&#x91CC;this&#x6307;&#x5411; {a: 7}</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token number">100</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</pre><p>&#x540C;&#x7406;&#xFF1A;</p>
<pre data-role="codeBlock" data-info="javascript" class="language-javascript"><span class="token keyword">var</span> bindf1 <span class="token operator">=</span> f1<span class="token punctuation">.</span><span class="token function">bind</span><span class="token punctuation">(</span><span class="token punctuation">{</span>a<span class="token punctuation">:</span> <span class="token number">8</span><span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span> 
<span class="token function">bindf1</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// 8 8</span>
</pre><h2 class="mume-header" id="%E6%80%BB%E7%BB%93">&#x603B;&#x7ED3;</h2>

<p>&#x7BAD;&#x5934;&#x51FD;&#x6570;&#x6CA1;&#x6709;&#x81EA;&#x5DF1;&#x7684;this&#xFF0C;&#x7BAD;&#x5934;&#x51FD;&#x6570;&#x4E2D;&#x7528;this&#x548C;&#x666E;&#x901A;&#x8BED;&#x53E5;&#x4E2D;&#x7684;this&#x6CA1;&#x4EC0;&#x4E48;&#x533A;&#x522B;&#xFF0C;&#x6240;&#x4EE5;&#xFF0C;&#x4F60;&#x77E5;&#x9053;&#x975E;&#x7BAD;&#x5934;&#x51FD;&#x6570;&#x4E0B;&#x600E;&#x4E48;&#x7528;this,&#x5C31;&#x77E5;&#x9053;&#x7BAD;&#x5934;&#x51FD;&#x6570;&#x4E0B;&#x600E;&#x4E48;&#x7528;this&#x3002;<br>
&#x5173;&#x4E8E; &#x201C;&#x7BAD;&#x5934;&#x51FD;&#x6570;&#x5BF9;this&#x56FA;&#x5B9A;&#x5316;&#xFF0C;&#x7BAD;&#x5934;&#x51FD;&#x6570;&#x4E2D;&#x7684;this&#x7ED1;&#x5B9A;&#x5B9A;&#x4E49;&#x65F6;&#x6240;&#x5728;&#x7684;&#x4F5C;&#x7528;&#x57DF;&#xFF0C;&#x7BAD;&#x5934;&#x51FD;&#x6570;&#x4E0D;&#x80FD;&#x901A;&#x8FC7; call() &#x6216; apply() &#x65B9;&#x6CD5;&#x7ED1;&#x5B9A;this&#x201D; &#x7B49;&#x63CF;&#x8FF0;&#xFF0C;&#x90FD;&#x6E90;&#x4E8E;&#x7BAD;&#x5934;&#x51FD;&#x6570;&#x6CA1;&#x6709;&#x81EA;&#x5DF1;&#x7684;this&#x3002;</p>

      </div>
      <div class="md-sidebar-toc"><ul>
<li><a href="#%E4%B8%80%E5%8F%A5%E8%AF%9D%E6%98%8E%E7%99%BD%E7%AE%AD%E5%A4%B4%E5%87%BD%E6%95%B0%E4%B8%AD%E7%9A%84this">&#x4E00;&#x53E5;&#x8BDD;&#x660E;&#x767D;&#x7BAD;&#x5934;&#x51FD;&#x6570;&#x4E2D;&#x7684;this</a><br>
* <a href="#%E7%AC%AC%E4%B8%80%E4%B8%AA%E7%A4%BA%E4%BE%8B">&#x7B2C;&#x4E00;&#x4E2A;&#x793A;&#x4F8B;&#xFF1A;</a><br>
* <a href="#%E7%AC%AC%E4%BA%8C%E4%B8%AA%E7%A4%BA%E4%BE%8B">&#x7B2C;&#x4E8C;&#x4E2A;&#x793A;&#x4F8B;&#xFF1A;</a><br>
* <a href="#%E7%AC%AC%E4%B8%89%E4%B8%AA%E7%A4%BA%E4%BE%8B">&#x7B2C;&#x4E09;&#x4E2A;&#x793A;&#x4F8B;&#xFF1A;</a><br>
* <a href="#%E7%AC%AC%E5%9B%9B%E4%B8%AA%E7%A4%BA%E4%BE%8B">&#x7B2C;&#x56DB;&#x4E2A;&#x793A;&#x4F8B;&#xFF1A;</a><br>
* <a href="#%E7%AC%AC%E4%BA%94%E4%B8%AA%E7%A4%BA%E4%BE%8B">&#x7B2C;&#x4E94;&#x4E2A;&#x793A;&#x4F8B;&#xFF1A;</a><br>
* <a href="#%E7%AC%AC%E5%85%AD%E4%B8%AA%E7%A4%BA%E4%BE%8B">&#x7B2C;&#x516D;&#x4E2A;&#x793A;&#x4F8B;&#xFF1A;</a>
<ul>
<li><a href="#%E6%80%BB%E7%BB%93">&#x603B;&#x7ED3;</a></li>
</ul>
</li>
</ul>
</div>
      <a id="sidebar-toc-btn">&#x2261;</a>
    
    
    
    
    
    
    
    
<script>

var sidebarTOCBtn = document.getElementById('sidebar-toc-btn')
sidebarTOCBtn.addEventListener('click', function(event) {
  event.stopPropagation()
  if (document.body.hasAttribute('html-show-sidebar-toc')) {
    document.body.removeAttribute('html-show-sidebar-toc')
  } else {
    document.body.setAttribute('html-show-sidebar-toc', true)
  }
})
</script>
      
  
    </body></html>